package com.lineage.william;

import com.lineage.DatabaseFactory;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.templates.L1Account;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.ArrayList;

public class ezpay {
  public static void getItem(L1PcInstance pc, long count) {
    Connection conn = null;
    try {
      conn = DatabaseFactory.get().getConnection();
      Statement stat = conn.createStatement();
      ResultSet rs = stat.executeQuery("SELECT * FROM ezpay_赞助累积金额");
      ArrayList arraylist = null;
      L1Account account = pc.getNetConnection().getAccount();
      int nowb = account.get_first_pay();
      if (rs != null)
        while (rs.next()) {
          int money = rs.getInt("money");
          int itemid = rs.getInt("give_item");
          int itemcount = rs.getInt("give_count");
          if ((int)count + nowb >= money && nowb < money) {
            L1ItemInstance items = pc.getInventory().storeItem(itemid, itemcount);
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fW累积赞助达满:" + money));
            pc.sendPackets((ServerBasePacket)new S_ServerMessage("\\fW赠礼:" + items.getName() + "(" + itemcount + ")"));
          } 
        }  
      if (conn != null && !conn.isClosed())
        conn.close(); 
    } catch (Exception exception) {}
  }
}
